package utils

import models.PDFImageModel
import org.apache.pdfbox.pdmodel.PDResources
import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject
import java.awt.image.BufferedImage

object PDFUtils {
    fun getImageFromResource(resource : PDResources) : List<PDFImageModel>
    {
        val imageList = ArrayList<PDFImageModel>()
        for (name in resource.xObjectNames)
        {
            val obj = resource.getXObject(name)
            if (obj is PDFormXObject)
            {
                imageList.addAll(getImageFromResource(obj.resources))
            }else if (obj is PDImageXObject)
            {
                imageList.add(PDFImageModel(obj.image,name.name))
            }
        }
        return  imageList
    }

}